#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: WANDERSON M.PIMENTA
@Software: PyCharm 、Qt Designer and PySide6
@File: tQMainWindowFunc.py
@Time: 2024/04/03 13:32
@Function：ctQMainWindowFunc：MainWindow中的功能函数
"""
import sys
from tQQtCore import *
from .tQMainWindowUI import *


# MainWindow布局中的功能函数
class ctQMainWindowFunc():
    # 初始化
    def __init__(self):
        super().__init__()
        # MainWindow GUI 界面实现
        self.ui = ctQMainWindowUI()
        self.ui.f_mainFormLayout(self)

    # 设置主窗口页面函数
    def f_setPageFunc(self, page):
        """
        function:  设置主窗口页面
              in:  page:widget类型
             out:  None
          return:  None
          others:  Set Main Window Page Func
        """
        self.ui.mainPages.pages.setCurrentWidget(page)

    # 设置左列菜单函数
    def f_setLeftColumnMenu(self, menu, title, icon_path):
        """
        function:  设置左列菜单函数
              in:  menu:菜单；
                   title：标题；
                   icon_path：icon路径
             out:  None
          return:  None
          others:  Set Left Column Menu Func
        """
        self.ui.leftColumn.menus.menus.setCurrentWidget(menu)
        self.ui.leftColumn.title_label.setText(title)
        self.ui.leftColumn.icon.f_leftColumnSetIcon(icon_path)

    # 获取左列是否可见函数
    def f_leftColumnIsVisibleFunc(self):
        """
        function:  获取左列是否可见函数
              in:  None
             out:  None
          return:  True Or False
          others:  Gets Whether Left Column Is Visible Func
        """
        width = self.ui.frameLeftColumn.width()
        if width == 0:
            return False
        else:
            return True

    # 获取右列是否可见函数
    def f_rightColumnIsVisibleFunc(self):
        """
        function:  获取右列是否可见函数
              in:  None
             out:  None
          return:  True Or False
          others:  Gets Whether Right Column Is Visible Func
        """
        width = self.ui.frameRightColumn.width()
        if width == 0:
            return False
        else:
            return True

    # 设置右列菜单函数
    def f_setRightColumnMenu(self, menu):
        """
        function:  设置右列菜单函数
              in:  menu:菜单；
             out:  None
          return:  None
          others:  Set Right Column Menu Func
        """
        self.ui.rightColumn.menus.setCurrentWidget(menu)

    # 获取标题栏按键函数
    def f_getTitleBarBtnFunc(self, object_name):
        """
        function:  获取标题栏按键函数
              in:  object_name：按键的objectName
             out:  None
          return:  None
          others:  Gets Title Bar Button Func
        """
        return self.ui.frameTitleBar.findChild(QPushButton, object_name)

    # 获取左侧菜单栏按键函数
    def f_getLeftMenuBarBtnFunc(self, object_name):
        """
        function:  获取左侧菜单栏按键函数
              in:  object_name：按键的objectName
             out:  None
          return:  None
          others:  Gets Left MenuBar Button Func
        """
        return self.ui.leftMenuBar.findChild(QPushButton, object_name)

    # 左列切换函数
    def f_toggleLeftColumnFunc(self):
        """
        function:  左列切换函数
              in:  None
             out:  None
          return:  None
          others:  Left Column Toggle Func
        """
        # GET ACTUAL CLUMNS SIZE
        width = self.ui.frameLeftColumn.width()
        right_column_width = self.ui.frameRightColumn.width()

        ctQMainWindowFunc.__f_columnAnimationFunc(self, width, right_column_width, "left")

    # 右列切换函数
    def f_toggleRightColumnFunc(self):
        """
        function:  右列切换函数
              in:  None
             out:  None
          return:  None
          others:  Right Column Toggle Func
        """
        # GET ACTUAL CLUMNS SIZE
        left_column_width = self.ui.frameLeftColumn.width()
        width = self.ui.frameRightColumn.width()

        ctQMainWindowFunc.__f_columnAnimationFunc(self, left_column_width, width, "right")

    # <editor-fold desc="该类用到的私有方法">
    # 左右列切换动画函数
    def __f_columnAnimationFunc(self, left_box_width, right_box_width, direction):
        """
        function:  左右列切换动画函数
              in:  left_box_width：左列宽度
                   right_box_width：右列宽度
                   direction："left" & "right
             out:  None
          return:  None
          others:  Left & Right Column Toggle Animation Func
        """
        right_width = 0
        left_width = 0
        time_animation = self.ui.settings["time_animation"]
        minimum_left = self.ui.settings["left_column_size"]["minimum"]
        maximum_left = self.ui.settings["left_column_size"]["maximum"]
        minimum_right = self.ui.settings["right_column_size"]["minimum"]
        maximum_right = self.ui.settings["right_column_size"]["maximum"]

        # Check Left Values
        if left_box_width == minimum_left and direction == "left":
            left_width = maximum_left
        else:
            left_width = minimum_left

        # Check Right values
        if right_box_width == minimum_right and direction == "right":
            right_width = maximum_right
        else:
            right_width = minimum_right

            # ANIMATION LEFT BOX
        self.left_box = QPropertyAnimation(self.ui.frameLeftColumn, b"minimumWidth")
        self.left_box.setDuration(time_animation)
        self.left_box.setStartValue(left_box_width)
        self.left_box.setEndValue(left_width)
        self.left_box.setEasingCurve(QEasingCurve.InOutQuart)

        # ANIMATION RIGHT BOX
        self.right_box = QPropertyAnimation(self.ui.frameRightColumn, b"minimumWidth")
        self.right_box.setDuration(time_animation)
        self.right_box.setStartValue(right_box_width)
        self.right_box.setEndValue(right_width)
        self.right_box.setEasingCurve(QEasingCurve.InOutQuart)

        # GROUP ANIMATION
        self.group = QParallelAnimationGroup()
        self.group.stop()
        self.group.addAnimation(self.left_box)
        self.group.addAnimation(self.right_box)
        self.group.start()

    # </editor-fold>
